package user;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.omg.DynamicAny.DynAnyOperations;

/**
 * Servlet implementation class User_updataPassServlet
 */
@WebServlet("/User_updataPassServlet")
public class User_updataPassServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public User_updataPassServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		response.setContentType("text/html; charset=UTF-8");
		response.setCharacterEncoding("utf-8");
		request.setCharacterEncoding("utf-8");
		//从视图上获取数据
		String uid_1 = request.getParameter("uid");
		int uid = Integer.parseInt(uid_1);
		String newPass = request.getParameter("newPW");
		/*System.out.println(newPass);
		System.out.println(uid);*/
		//把数据送到javaBean去执行
		UserDao dao = new UserDao();
		//密码加密
		String Np = dao.string2MD5(newPass);
		int result = dao.doUpdatePassword(uid, Np);
		if(result >= 0) {
			response.getWriter().print("<script type=\"text/javascript\">alert(\"密码修改成功！\");window.location=\"/Lesson_310/content/welcome.jsp\";</script>");
			return;
		}else {
			response.sendRedirect("/Lesson_310/user/user_success.jsp?count=1");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
